//
//  JYWalletViewController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/11.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYWalletViewController.h"
#import "JYMineMenuCell.h"
#import "JYMPointDetaController.h"
#import "JYRechargeController.h"
@interface JYWalletViewController ()
@property(nonatomic)NSArray *titleArr;
@property(nonatomic)NSArray *imgArr;

@end

static NSString *const WallectCellID = @"WallectCellID";
@implementation JYWalletViewController
#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}
#pragma mark - initUI
- (void)initUI{
    self.title =  @"我的钱包";
    self.titleArr = @[@"美点支付",@"美点明细"];
    self.imgArr = @[@"mine_purse_recharge",@"mine_purse_detail"];
    JYWalletHeaderView *headerView = [[JYWalletHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 180)];
    headerView.moneyLabel.text = @"8655485.98";
    self.tableView.tableHeaderView = headerView;
    [self.tableView registerClass:[JYMineMenuCell class] forCellReuseIdentifier:WallectCellID];
    self.tableView.tableFooterView = [UIView new];
}
#pragma mark - <UITableViewDataSource,UITableViewDelegate>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return [self.titleArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JYMineMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:WallectCellID];
    
        cell.titleLabel.text = [self.titleArr safeObjectAtIndex:indexPath.row];
        cell.iconImage.image =[UIImage imageNamed:[self.imgArr safeObjectAtIndex:indexPath.row]];
  
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
       
        [self.navigationController pushViewController:[JYRechargeController new] animated:YES];
    }else if(indexPath.row ==1){
    
        [self.navigationController pushViewController:[JYMPointDetaController new] animated:YES];
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1;
}


@end

@interface JYWalletHeaderView ()
//图片
@property(nonatomic)UIImageView *imgView;

//美点余额
@property(nonatomic)UILabel *pointLabel;

@end


@implementation JYWalletHeaderView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self setupSubView];
    }
    return self;

}
- (void)setupSubView{

    [self addSubview:self.imgView];
    [self.imgView addSubview:self.moneyLabel];
    [self.imgView addSubview:self.pointLabel];

}
- (void)layoutSubviews{
    
    [super layoutSubviews];
    JYWeakSelf;
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerX .equalTo(weakSelf);
        make.centerY .equalTo(weakSelf);
//        make.top.left.mas_equalTo(0);
//        make.width.mas_equalTo(weakSelf.mas_width);
//        make.height.mas_equalTo(weakSelf.mas_height);
    }];
    [self.moneyLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX .equalTo(weakSelf);
        make.centerY .equalTo(weakSelf);
    }];
  
    [self.pointLabel  mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX .equalTo(weakSelf);
        make.centerY .equalTo(weakSelf).offset(20);
    }];
    
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [[UIImageView alloc]init];
        _imgView.image = [UIImage imageNamed:@"mine_purse_balance"];
        
    }
    return _imgView;
}
- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [UILabel labelText:@"" fontSize:21 textColor:kfColor textAlignment:NSTextAlignmentCenter];
    }
    return _moneyLabel;

}
- (UILabel *)pointLabel{

    if (!_pointLabel) {
        _pointLabel =[UILabel labelText:@"美点余额" fontSize:12 textColor:kfColor textAlignment:NSTextAlignmentCenter];
    }
    return _pointLabel;

}
@end

